<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>14.v-if和v-show指令</title>
    <script src="./lib/vue-2.6.12.js"></script>
</head>

<body>
    <div id="app">
        <button @click="toggle">切换</button>
        <button @click="flag=!flag">切换2</button>
        <!-- v-if 每次都会删除或创建元素，有较高的切换效能消耗 -->
        <h3 v-if="flag">这是 v-if 控制的元素</h3>
        <!-- v-show 每次只是修改 display:none 样式，切换性能高消耗少，但是有较高的初始渲染消耗 -->
        <h3 v-show="flag">这是 v-show 控制的元素</h3>
    </div>

    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                flag: true
            },
            methods: {
                toggle() {
                    this.flag = !this.flag;
                }
            }
        })        
    </script>
</body>

</html>